package com.codechuan.demo.thread;


import com.codechuan.demo.common.Constant;
import com.codechuan.demo.dto.Schedule;
import com.codechuan.demo.dto.SuccessOrder;
import com.codechuan.demo.floatWindowManager.log.LogManager;
import com.codechuan.demo.utils.DateUtil;
import com.codechuan.demo.utils.HttpControllerUtil;

/**
 * @Deprecated 获取订单线程
 */
public class RobOrderThread implements Runnable {

    SynContainer synContainer;

    public RobOrderThread(SynContainer synContainer) {
        this.synContainer = synContainer;
    }

    @Override
    public void run() {
        while (Constant.isStart) {
            SuccessOrder successOrder = this.synContainer.getSuccessOrder();
            if (successOrder != null) {
                if (Constant.APP_IS_CHECK || Constant.XCX_IS_CHECK) {
                    if (Constant.ZD_FB_XC) {
                        LogManager.get().addLog("正在执行抢单发布行程起点是:" + successOrder.getStartAddress()
                                + "\t终点是:" + successOrder.getEndEndLongAddr());
                        // 发布一个行程
                        Schedule schedule = new Schedule();
                        schedule.setStartCityCode(successOrder.getCityCode());
                        schedule.setStartAdCode(successOrder.getAdCode());
                        schedule.setStartShortAddr(successOrder.getShortAddr());
                        schedule.setStartLon(Double.parseDouble(successOrder.getLon()));
                        schedule.setStartLat(Double.parseDouble(successOrder.getLat()));
                        schedule.setStartLongAddr(successOrder.getStartAddress());
                        schedule.setStartCityName(successOrder.getCityName());

                        schedule.setEndCityCode(successOrder.getEndCityCode());
                        schedule.setEndAdCode(successOrder.getEndAdCode());
                        schedule.setEndShortAddr(successOrder.getEndShortAddr());
                        schedule.setEndLon(Double.parseDouble(successOrder.getEndLon()));
                        schedule.setEndLat(Double.parseDouble(successOrder.getEndLat()));
                        schedule.setEndLongAddr(successOrder.getEndLongAddr());
                        schedule.setEndCityName(successOrder.getEndCityName());
                        // 时间错转时间
                        String time1 = successOrder.getTime();
                        schedule.setTime(String.valueOf(DateUtil.stringTimeParseLongTimeTwo(time1)));
                        String driverJourneyGuid = HttpControllerUtil.submit_WeChatMini(schedule);
                        if (driverJourneyGuid != null) {
                            successOrder.setDriverJourneyGuid(driverJourneyGuid);
                            Constant.driverJourneyGuids.add(driverJourneyGuid);
                        }
                        LogManager.get().addLog("发布行程成功开始远程服务器抢单");
                        Constant.executorService.execute(new DeleteSubMitXc());

                    }
                    HttpControllerUtil.submitWeChatAppOrder(successOrder);
                }
                if (Constant.XCX_IS_CHECK) {
                    HttpControllerUtil.submitWeChatAppOrder(successOrder);
                }
                successOrder.setOk(true);
            }
        }
    }
}
